package com.vcs.frm.web.school;

import javax.validation.Valid;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.vcs.frm.web.form.SchoolLoginForm;

@Controller
@RequestMapping("schoolLogin")
public class SchoolLoginController {

	Log log = LogFactory.getLog(this.getClass());
	
	@RequestMapping(method = RequestMethod.GET)
	public String showSchoolLoginForm(Model model) {

		SchoolLoginForm schoolLogin = new SchoolLoginForm();
		
		model.addAttribute("schoolLogin", schoolLogin);
		log.info("SchoolLoginController - showSchoolLoginForm");
		return "schoolLogin";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String processSchoolLoginForm(
			@ModelAttribute("schoolLogin") @Valid SchoolLoginForm schoolLogin,
			BindingResult bindingResult,
			Model model) {

		log.info(bindingResult);
		model.addAttribute("schoolLogin", schoolLogin);
		if (bindingResult.hasErrors()) {
			return "schoolLogin";
		}
		
		
		System.out.println("************************************");
		return "schoolHome";
	}
}
